package xyz.riceball.common.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import xyz.riceball.common.entity.po.SysConfigPO;
import xyz.riceball.common.service.SysConfigService;
import xyz.riceball.framework.core.annotation.RbLog;
import xyz.riceball.framework.core.annotation.RbSysRequest;
import xyz.riceball.framework.core.bean.ApiController;
import xyz.riceball.framework.core.bean.ApiR;

import javax.annotation.Resource;

/**
 * <p>
 * 系统参数控制类
 * </p>
 *
 * @author xiaovcloud
 * @since 2022/5/28 15:50
 */
@Api(tags = "系统管理")
@RestController
@RequestMapping("/rb/api/sys/config")
@RbSysRequest
public class SysConfigController extends ApiController {

    @Resource
    private SysConfigService sysConfigService;

    /**
     * 获取所有系统参数
     *
     * @return
     */
    @ApiOperation("获取系统信息")
    @GetMapping
    @RbLog(description = "获取系统信息")
    public ApiR<SysConfigPO> selectAll() {
        SysConfigPO result = sysConfigService.list().get(0);
        return success(result);
    }

    @ApiOperation("修改系统信息")
    @PutMapping
    @RbLog(description = "修改系统信息")
    public ApiR<Void> editConfig(SysConfigPO sysConfigPO) {
        boolean result = sysConfigService.updateById(sysConfigPO);
        return ApiR.msg(result, "修改系统参数成功", "修改系统参数失败");
    }

}
